<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>订单列表</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.table td {
			vertical-align: middle;
			background-color: #FFF;
			border: 0px;
			padding: 0px;
			border: none;
		}
		.bg_white{background-color: white;}
		.td_title{ font-weight: bold;}
		#one li a{padding-top: 0px; padding-bottom: 0px;}
		.p_ellipsis{ width: 130px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
		.led_label{height: 16px;width: 60px;vertical-align: middle;text-align: center;}
	</style>
	<script type="text/javascript">
		var _lastPage="false";
		var $selectAll = false;
		$(document).ready(function() {
			_lastPage = ${page.lastPage};
			if('${type}'=='1'){
				top.$.jBox.close();
			}
			gotoTop();
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
        //查看详情  id:订单ID
        function showDetail(id){
        	top.$.jBox.defaults.top="8%";
        	top.$.jBox.open("iframe:${ctx}/ivm/order/orderDetail?id="+id, "订单详情",$(top.document).width()-500,$(top.document).height()-100,{
				buttons:{"确定":true}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
        }
        function selectAll(){
			$("input[name='orderId']").each(function(){
				$(this).attr("checked", $("#select_all").is(':checked'));
			});
			if($selectAll){
				$selectAll= false;
			}else{
				$selectAll= true;
			}
		}
        //查看送货详情  id:订单ID
        function showDeliveryDetail(id, orderNo){
        	top.$.jBox.defaults.top="8%";
        	top.$.jBox.open("iframe:${ctx}/ivm/order/delivery/deliveryInfo?id="+id, "订单："+orderNo+"—送货单",$(top.document).width()-500,$(top.document).height()-100,{
				buttons:{"确定":true}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
        }
		//生成采购清单
		function showPurchaseOrder(){
			if($("input[name='orderId']:checked").length==0){
				showJBoxMess("请选择要操作的订单.","error");
				return;
			}
			var orderIds = "";
			$("input[name='orderId']").each(function(){
				if($(this).is(":checked")){
					orderIds+=",'"+$(this).val()+"'";
				}
			});
			if(orderIds!="") orderIds = orderIds.substring(1);
			showJBoxMess("正在获取清单列表.","success");
			setTimeout(function(){
				top.$.jBox.defaults.top="8%";
				top.$.jBox.open("iframe:${ctx}/ivm/purchase/showPurchaseOrder?orderIds="+orderIds, "采购清单明细",$(top.document).width()-350,$(top.document).height()-100,{
					buttons:{"确定":true}, loaded:function(h){
						$(".jbox-content", top.document).css("overflow-y","hidden");
					}
				});
			}, 2000);
		}
		//生成配货清单
		function showDistributionOrder(){
			if($("input[name='orderId']:checked").length==0){
				showJBoxMess("请选择要操作的订单.","error");
				return;
			}
			var orderIds = "";
			$("input[name='orderId']").each(function(){
				if($(this).is(":checked")){
					orderIds+=",'"+$(this).val()+"'";
				}
			});
			if(orderIds!="") orderIds = orderIds.substring(1);
			showJBoxMess("正在获取清单列表.","success");
			setTimeout(function(){
				top.$.jBox.defaults.top="8%";
				top.$.jBox.open("iframe:${ctx}/ivm/purchase/showDistributionOrder?orderIds="+orderIds, "配货清单明细",$(top.document).width()-350,$(top.document).height()-100,{
					buttons:{"确定":true}, loaded:function(h){
						$(".jbox-content", top.document).css("overflow-y","hidden");
					}
				});
			}, 2000);
		}
        //指定送货员
		function createDeliveryIndent(id){
			var orderIds = "";
			if(id != undefined){
				orderIds = ","+id;
			}else{
				if($("input[name='orderId']:checked").length==0){
					showJBoxMess("请选择要操作的订单.","error");
					return;
				}
				$("input[name='orderId']").each(function(){
					var delIndentId = $(this).parent().find("#delIndentId").val();
					if($(this).is(":checked") && delIndentId==''){
						orderIds+=","+$(this).val();
					}
				});
			}
			if(orderIds!="") orderIds = orderIds.substring(1);
			top.$.jBox.defaults.top="32%";
        	top.$.jBox.open("iframe:${ctx}/ivm/order/delivery/setDeliveryMember?orderIds="+orderIds, "指定送货员",$(top.document).width()-800,$(top.document).height()-300,{
				buttons:{"确定":true}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//批量送货员签出
		function checkout(orderId){
			if(orderId==''){
				if($("input[name='orderId']:checked").length==0){
					showJBoxMess("请选择要操作的订单.","error");
					return;
				}
				var orderIds = "";
				$("input[name='orderId']").each(function(){
					var delIndentId = $(this).parent().find("#delIndentId").val();
					if($(this).is(":checked") && delIndentId!=''){
						orderIds+=","+$(this).val();
					}
				});
				if(orderIds==""){
					showJBoxMess("请选择已指定送货员的订单.","error");
					return;
				}else{
					orderIds = orderIds.substring(1);
				}
				top.$.jBox.confirm("确认送货员签出订单",'系统提示',function(v,h,f){
					if(v=='ok'){
						loading('正在提交，请稍等...');
						//开始签出
						//异步检测
						$.ajax({
							type: 'get',
							url: '${ctx}/ivm/order/delivery/checkout',
							data: 'orderIds='+orderIds,
							dataType: 'json',
							success: function(data){
								if(data.status==200){
									showJBoxMess("送货员签出成功.","success");
									$("#searchForm").submit();
								}else{
									showJBoxMess(data.message,"error");
								}
							},
							failure: function(){
								showJBoxMess("操作失败","error");
							}				
						});
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			}else{
				//送货员签出
				top.$.jBox.defaults.top="22%";
				top.$.jBox.open("iframe:${ctx}/ivm/order/delivery/showCheckoutPanl?id="+orderId, "送货员签出",360,200,{
					buttons:{"确定":false}, loaded:function(h){
						$(".jbox-content", top.document).css("overflow-y","hidden");
					}
				});
			}
		}
		//批量完成订单
		function finishOrders(){
			if($("input[name='orderId']:checked").length==0){
				showJBoxMess("请选择要操作的订单.","error");
				return;
			}
			var orderIds = "";
			$("input[name='orderId']").each(function(){
				var orderType = $(this).parent().find("#orderType").val();
				var delFlag = $(this).parent().find("#delFlag").val();
				var canDelivery = $(this).parent().find("#canDelivery").val();
				if($(this).is(":checked") && orderType!='2' && delFlag!='1' && canDelivery=='true'){
					orderIds+=","+$(this).val();
				}
			});
			if(orderIds==""){
				showJBoxMess("请选择未完成的订单.","error");
				return;
			}else orderIds = orderIds.substring(1);
			//执行提示
			var href = "${ctx}/ivm/order/finishOrder?id="+orderIds;
			return confirmx('确认完成选择的订单吗？', href);
		}
		function selectOrderType(value){
			if($("#pageNo").val()>1){
				$("#pageNo").val(1);
			}
			$('#orderType').val(value);
			$('#searchForm').submit();
		}
		//完成订单deliveryAmount:应收金额，refund:应退金额
		//type=0：正常完成订单，type==1：复核完成订单
		function finishOrder(orderId){
			top.$.jBox.defaults.top="24%";
			top.$.jBox.open("iframe:${ctx}/ivm/order/showFinishOrderPanl?id="+orderId, "完成订单",$(top.document).width()-800,$(top.document).height()-200,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		function finishOrder1(orderId,workflowNode,orderNo,deliveryAmount,refund,type){
			var text1="应收金额";text2="实收金额";amount=deliveryAmount;
			if(workflowNode=='5'){
				text1="应退金额";text2="实退金额";
				amount = refund;
			}
			var html = '<div style="padding:10px 20px 0px 20px;"><span class="color-red font-size20">*</span>签收时间：<input type="text" id="signTime" name="signTime" style="width:220px"';
			html += 'value="<fmt:formatDate value="${order.deliveryInfo.signTime}" pattern="yyyy-MM-dd HH:mm"/>"';
			html += 'onclick="WdatePicker({dateFmt:\'yyyy-MM-dd HH:mm\',isShowClear:true});"/></div>';
			html += '<div style="padding:0px 20px;"><span class="font-size20">&nbsp;</span>订单金额：'+deliveryAmount+'元　　'+text1+'：'+amount+'元</div>';
			html += '<div style="padding:0px 20px;"><span class="color-red font-size20">*</span>'+text2+'：<input type="text" id="realAmount" name="realAmount">元</div>';
			html += '<div style="padding:0px 20px;"><span class="font-size20">&nbsp;</span>备　　注：<textarea type="text" id="marks" name="marks" style="width:220px"/></div>';
			var submit = function (v, h, f) {
				if (f.signTime == '') {
					top.$.jBox.tip("请输入签收时间。", 'error', { focusId: "signTime" });
			        return false;
			    }
			    if (f.realAmount == '') {
					top.$.jBox.tip(text2, 'error', { focusId: "realAmount" });
			        return false;
			    }
				var href="${ctx}/ivm/order/finishOrder?id="+orderId+"&receiptMarks="+URLencode(f.marks)+"&signTime="+f.signTime+"&type="+type+"&realAmount="+f.realAmount;
			    return confirmx('确认完成此订单吗？', href);
			    top.$.jBox.close();
			};
			top.$.jBox.defaults.top="23%";
			top.$.jBox(html, { title: "收货信息", submit: submit });
			//打开送货单
			//showDeliveryDetail(orderId, orderNo)
		}
		//财务结账
		function finishPay(orderId){
			top.$.jBox.defaults.top="22%";
			top.$.jBox.open("iframe:${ctx}/ivm/order/showFinishPayPanl?id="+orderId, "解款信息",$(top.document).width()-800,$(top.document).height()-200,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		function finishPay1(orderId,workflowNode,deliveryAmount,refund,realRefund){
			var text1="应收金额";text2="实收金额";amount=deliveryAmount;
			if(workflowNode=='6'){
				text1="应退金额";text2="实退金额";
				amount = refund;
			}
			var html = '<div style="padding:5px 20px;"><span class="font-size20">&nbsp;</span>订单金额：'+deliveryAmount+'元</div>';
			html += '<div style="padding:5px 20px;"><span class="font-size20">&nbsp;</span>'+text1+'：'+amount+'元</div>';
			html += '<div style="padding:5px 20px;"><span class="font-size20">&nbsp;</span>'+text2+'：'+realRefund+'元</div>';
			html += '<div style="padding:0px 20px;"><span class="color-red font-size20">*</span>解款密码：<input type="text" id="payCode" name="payCode"></div>';
			html += '<div style="padding: 0px 20px 10px 80px;"><span class="font-size20">&nbsp;</span>'
			html += '<input id="finish" name="finish" value="1" checked="checked" type="radio"><label for="finish">同意解款</label>';
			html += '<input id="finish1" name="finish" value="2" type="radio"><label for="finish1">退回复核</label>';
			html += '</div>';
			var submit = function (v, h, f) {
				if (f.payCode == '') {
					top.$.jBox.tip("请输入结账密码。", 'error', { focusId: "payCode" });
			        return false;
			    }
			    if($("input[id='payKey']").val() != f.payCode){
			    	top.$.jBox.tip("密码错误，请重新输入。", 'error', { focusId: "payCode" });
			        return false;
			    }
				var href="${ctx}/ivm/order/finishPayOrder?id="+orderId+"&finish="+f.finish;
			    return confirmx('确认提交吗？', href);
			    top.$.jBox.close();
			};
			top.$.jBox.defaults.top="27%";
			top.$.jBox(html, { title: "解款信息", submit: submit });
		}
		//修改支付方式
		function openPayType(id){
			top.$.jBox.defaults.top="27%";
			top.$.jBox.open("iframe:${ctx}/ivm/order/showPayType?id="+id, "支付方式",$(top.document).width()-800,$(top.document).height()-300,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//订单导出
		function exportOrder(orderId){
			var orderIds = "";
			var chk_value =""; 
			if(orderId==''){
				if($("input[name='orderId']:checked").length==0){
					showJBoxMess("请选择要操作的订单.","error");
					return;
				}
				$("input[name='orderId']").each(function(){
					if($(this).is(":checked")){
						orderIds+=","+$(this).val();
					}
				});
				orderIds = orderIds.substring(1);
				//查询条件的时间段
				$("input[name='timeVal']:checked").each(function(){
					chk_value+=","+$(this).val();
				}); 
				if(chk_value != ""){
					chk_value = chk_value.substring(1);
				}
			}else{
				orderIds = orderId;
			}
			$("input[id='orderIds']").val(orderIds);
			$("input[id='timeSlot']").val(chk_value);
			var param = "orderIds="+$("input[id='orderIds']").val();
			if($selectAll){//如果是全选，则根据查询条件全部导出
				param = "orderType="+$('#orderType').val();
				param += "&createStartDate="+$("#createStartDate").val();
				param += "&createEndDate="+$("#createEndDate").val();
				param += "&searchParam="+URLencode($("#searchParam").val());
				param += "&memberId"+$("#memberId").val();
			}
			param += "&timeSlot="+$("input[id='timeSlot']").val();
			top.$.jBox.defaults.top="22%";
			top.$.jBox.confirm("确认要导出订单明细？","系统提示",function(v,h,f){
				if(v=="ok"){
					$.ajax({
						type: 'post',
						url: '${ctx}/ivm/order/export',
						data: param,
						dataType: 'json',
						success: function(data){
							if(data.status==200){
								document.location.href= '${ctx}/download?filePath='+URLencode(data.message);
							}else{
								showJBoxMess(data.message,"error");
							}
						},
						failure: function(){
							showJBoxMess("操作失败","error");
						}
					});
				}
			},{buttonsFocus:1});
			top.$('.jbox-body .jbox-icon').css('top','55px');
		}
		//送货单导出Word
		function exportWord(orderId){
			var orderIds = "";
			var chk_value = "";
			if(orderId==''){
				if($("input[name='orderId']:checked").length==0){
					showJBoxMess("请选择要操作的订单.","error");
					return;
				}
				$("input[name='orderId']").each(function(){
					if($(this).is(":checked")){
						orderIds+=","+$(this).val();
					}
				});
				orderIds = orderIds.substring(1);
				//查询条件的时间段
				$("input[name='timeVal']:checked").each(function(){
					chk_value+=","+$(this).val();
				}); 
				if(chk_value != ""){
					chk_value = chk_value.substring(1);
				}
			}else{
				orderIds = orderId;
			}
			$("input[id='orderIds']").val(orderIds);
			$("input[id='timeSlot']").val(chk_value);
			var param = "orderIds="+$("input[id='orderIds']").val();
			if($selectAll){//如果是全选，则根据查询条件全部导出
				param = "orderType="+$('#orderType').val();
				param += "&createStartDate="+$("#createStartDate").val();
				param += "&createEndDate="+$("#createEndDate").val();
				param += "&searchParam="+URLencode($("#searchParam").val());
				param += "&memberId"+$("#memberId").val();
			}
			param += "&timeSlot="+$("input[id='timeSlot']").val();
			top.$.jBox.defaults.top="22%";
			top.$.jBox.confirm("确认要导出送货单word？","系统提示",function(v,h,f){
				if(v=="ok"){
					$.ajax({
						type: 'post',
						url: '${ctx}/ivm/order/exportWord',
						data: param,
						dataType: 'json',
						success: function(data){
							if(data.status==200){
								document.location.href= '${ctx}/download?filePath='+URLencode(data.message);
							}else{
								showJBoxMess(data.message,"error");
							}
						},
						failure: function(){
							showJBoxMess("操作失败","error");
						}
					});
				}
			},{buttonsFocus:1});
			top.$('.jbox-body .jbox-icon').css('top','55px');
		}

		var isLoadOver=0;//判断滑动是否已加载完成
		$(window).scroll(function(){  
		    // 当滚动到最底部以上100像素时， 加载新内容  
		    if ($(document).height() - $(this).scrollTop() - $(this).height()<100){
		    	if(isLoadOver == 0){
		    		isLoadOver == 1;
			    	loadMore();  
		    	}
		    }
		}); 
		//加载更多
		function loadMore(){
			if(_lastPage){
				return;
			}
			loading('正在加载，请稍等...');
			setTimeout(function () {
				//获取下一页数据
				$("#pageNo").val(parseInt($("#pageNo").val())+1);
				var param = "pageNo="+$("#pageNo").val()+"&pageSize="+$("#pageSize").val();
				param += "&orderType="+$('#orderType').val();
				param += "&createStartDate="+$("#createStartDate").val();
				param += "&createEndDate="+$("#createEndDate").val();
				param += "&searchParam="+URLencode($("#searchParam").val());
				param += "&timeSlot="+$("input[name='timeSlot']").val();
				param += "&memberId"+$("#memberId").val();
				//异步获取更多
				$.ajax({
					type: 'post',
					url: '${ctx}/ivm/order/list/more',
					data: param,
					dataType: 'json',
					success: function(data){
						if(data!=null){
							var list = data.list;
							if(data.lastPage){
							 	_lastPage = data.lastPage;
							}
							for(var i=0; i<list.length; i++){
								var order = list[i];
								var html = '<table id="contentTable" class="table table-bordered table-condensed" style="border-top: none; border-right: none; border-left: none; margin-bottom: 0px; padding-top:5px; padding-bottom: 5px;">';
								html += '<colgroup><col width="50px"><col width="80px"><col width="90px"><col width="70px"><col width="100px"><col width="70px"><col width="120px"><col width="70px"><col width="400px"></colgroup>';
								html += '<tr><td rowspan="4"  style="text-align: center;">';
								if(order.delFlag != "1"){
									html += '<input type="checkbox" id="orderId" name="orderId" value="'+order.id+'" />';
								}
								if(order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.id != '' && order.deliveryIndent.deliveryMember != null){
									html += '<input type="hidden" id="delIndentId" name="delIndentId" value="'+order.deliveryIndent.deliveryMember.id+'"/>';
								}else{
									html += '<input type="hidden" id="delIndentId" name="delIndentId" value=""/>';
								}
								html += '<input type="hidden" id="orderType" name="orderType" value="'+order.orderType+'"/>';
								html += '<input type="hidden" id="delFlag" name="delFlag" value="'+order.delFlag+'"/>';
								html += '<input type="hidden" id="canDelivery" name="canDelivery" value="'+order.canDelivery+'"/>';
								html += '</td>';
								html += '<td>'+order.name+'</td>';
								html += '<td>'+order.phone+'</td>';
								html += '<td>订单编号：</td>';
								html += '<td>';
								html += '<a href="javascript:" onclick="showDetail(\''+order.id+'\')">'+order.orderNo+'</a>';
								html += '</td>';
								html += '<td>下单时间：</td>';
								html += '<td>'+order.createDateStr+'</td>';
								html += '<td style="text-align: center;">';
								html += '<a href="javascript:" onclick="showDetail(\''+order.id+'\')">订单详情</a>';
								html += '</td>';
								html += '<td rowspan="4" style="text-align: center;">';
								if(order.workflowNode==1){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/1.png" height="50" width="400"/>';
								}else if(order.workflowNode==2){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/2.png" height="50" width="400"/>';
								}else if(order.workflowNode==3){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/3.png" height="50" width="400"/>';
								}else if(order.workflowNode==4){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/4.png" height="50" width="400"/>';
								}else if(order.workflowNode==5){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/5.png" height="50" width="400"/>';
								}else if(order.workflowNode==6){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/6.png" height="50" width="400"/>';
								}else if(order.workflowNode==7){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/7.png" height="50" width="400"/>';
								}else if(order.workflowNode==8){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/8.png" height="50" width="400"/>';
								}else if(order.workflowNode==9){
									html += '<img src="${ctxFront }/images/orderWorkFlow/small/9.png" height="50" width="400"/>';
								}
								html += '</td>';
								html += '</tr><tr>';
								html += '<td>会员等级：</td><td>暂无</td><td>订单金额：</td>';
								if(order.deliveryInfo==null){
									html += '<td>'+order.amount+'元</td>';
								}else{
									html += '<td>'+order.deliveryInfo.amount+'元</td>';
								}
								html += '<td>付款方式：</td>';
								html += '<td>';
								var payType = "";
								if(order.payType==1){
									payType = "货到付款";
								}else if(order.payType==2){
									payType = "支付宝";
								}else if(order.payType==3){
									payType = "银联";
								}else if(order.payType==4){
									payType = "微信";
								}
								html += '<a href="javascript:" onclick="openPayType(\''+order.id+'\')">'+payType+'</a>';
								html += '</td>';
								html += '<td style="text-align: center;">';
								if(order.delFlag=="0" && order.confirm=="1"){
									html += '<a href="javascript:" onclick="showDeliveryDetail(\''+order.id+'\',\''+order.orderNo+'\')">送货单</a>';
								}
								html += '</td></tr><tr><td>上月订单数：</td><td>暂无</td><td>收货时间：</td>';
								html += '<td>'+order.orderTimeText+'</td>';
								html += '<td>送货员：</td><td>';
								if(order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.deliveryMember != null && order.deliveryIndent.deliveryMember.id != ""){
									html += order.deliveryIndent.deliveryMember.name;
								}else{
									html += '暂未分配';
								}
								
								html += '</td>';
								html += '<td style="text-align: center;">';
								if(order.canDelivery && order.delFlag=='0' && order.orderType!='2'){
									html += '<label title="库存有货" class="led_label" style="background-color: green;">库存</label>';
								}
								if(!order.canDelivery && order.delFlag=='0' && order.orderType!='2'){
									html += '<label title="库存不足" class="led_label" style="background-color: red;">库存</label>';
								}
								html += '</td></tr><tr><td>平均客单价：</td><td>暂无</td><td>备注：</td>';
								var remark = "";
								if(order.remarks != undefined){
									remark = order.remarks;
								}
								html += '<td><p class="p_ellipsis" style="margin: 0px;" title="'+remark+'">'+remark+'</p></td>';
								html += '<td colspan="2">';
								var orderTypeValue = '';
								if(order.delFlag=='0'){
									if(order.payStatus=='0' && order.payType != '1'){
										orderTypeValue='等待付款';
									}
									if(((order.payStatus=='0' && order.payType == '1') || order.payStatus=='1') && order.confirm=='0'){
										orderTypeValue='<a href="javascript:" onclick="showDetail(\''+order.id+'\')">等待确认</a>';
										
									}
									if(order.confirm=='1'){
										if((order.payStatus=='0' && order.payType == '1') || order.payStatus=='1'){
											if(!(order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.deliveryMember != null && order.deliveryIndent.deliveryMember.id != '')){
												orderTypeValue='<a href="javascript:" onclick="createDeliveryIndent(\''+order.id+'\')">指定送货员</a>';
											}
										}
										if(order.orderType=='0' && (order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.id != '') && order.delFlag=='0'){
											orderTypeValue = '<a href="javascript:" onclick="checkout(\''+order.id+'\')">送货员签出</a>';
										}
										if(order.workflowNode=='5' || order.workflowNode=='8'){
											orderTypeValue = '<a href="javascript:" onclick="finishOrder(\''+order.id+'\')">订单完成</a>';
										}
										if(order.workflowNode=='6' || order.workflowNode=='9'){
											if(order.finish=='0'){
												orderTypeValue = '<a href="javascript:" onclick="finishPay(\''+order.id+'\')">解款</a>';
											}else if(order.finish=='1'){
												orderTypeValue = '<span style="color: green;">订单已完成</span>';
											}else if(order.finish=='2'){
												orderTypeValue = '<a href="javascript:" onclick="finishOrder(\''+order.id+'\')">等待复核</a>';
											}
										}
									}
								}else{
									orderTypeValue = '<span style="color: green;">订单已取消</span>';
								}
								html += orderTypeValue;
								html += '</td>';
								html += '<td style="text-align: center;">';
								if(order.orderType!='2' && order.delFlag=='0'){
									html += '<a href="javascript:;" onclick="cancelOrder(\''+order.id+'\')">取消订单</a>';
								}
								html += '</td></tr></table>';
				    			$("#listForm").append(html);
							}
						}
						top.$.jBox.closeTip();
						isLoadOver = 0;
					},
					failure: function(){
						top.$.jBox.closeTip();
					}
				});
			}, 500);
			isLoadOver = 1;
		}
		//返回顶部
		function gotoTop(){
		    $(".gotoTop").click(//定义返回顶部点击向上滚动的动画
		        function(){$('html,body').animate({scrollTop:0},500);
		    });
		    //为窗口的scroll事件绑定处理函数
		    $(window).scroll(function(){
		        //获取窗口的滚动条的垂直位置
		        var s = $(window).scrollTop();
		        //当窗口的滚动条的垂直位置大于页面的最小高度时，让返回顶部元素渐现，否则渐隐
		        if( s > 500){
		            $(".gotoTop").show();
		        }else{
		            $(".gotoTop").hide();
		        }
		    });
		};
		//取消订单
		function cancelOrder(id){
			top.$.jBox.defaults.top="22%";
			top.$.jBox.open("iframe:${ctx}/ivm/order/showCancelPanl?id="+id, "取消订单",360,200,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//查询
		function search(){
			var chk_value = "";
			//查询条件的时间段
			$("input[name='timeVal']:checked").each(function(){
				chk_value+=","+$(this).val();
			}); 
			if(chk_value != ""){
				chk_value = chk_value.substring(1);
			}
			$("input[id='timeSlot']").val(chk_value);
			if($("#pageNo").val()>1){
				$("#pageNo").val(1);
			}
			$("#searchForm").submit();
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/ivm/order/list">订单列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="order" action="${ctx}/ivm/order/list" method="post" class="breadcrumb form-search">
		<input type="hidden" id="orderIds" name="orderIds" value=""/>
		<input type="hidden" id="timeSlot" name="timeSlot" value=""/>
		<input id="payKey" name="payKey" type="hidden" value="${order.merchant.payCode}"/>
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<form:hidden path="orderType"/>
		<tags:message content="${message}"/>
		<ul class="nav nav-tabs" style="margin-bottom: 10px;" id="one">
			<c:forEach items="${fns:getDictList('ivm_orderType')}" var="item">
				<c:if test="${item.value != 3 && item.value != 4}">
				<li class="${order.orderType==item.value?'active':''}"><a href="#" onclick="selectOrderType('${item.value}')">${item.label }</a></li>
				</c:if>
			</c:forEach>
		</ul>
		<!--<label style="margin-bottom: 10px;">订单状态：</label>
		<form:radiobuttons onclick="$('#searchForm').submit();" path="orderType" items="${fns:getDictList('ivm_orderType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>-->
		<label style="margin-bottom: 15px;">搜索条件：</label>
		<input id="searchParam" name="searchParam" type="text" value="${searchParam }" style="width: 410px;" placeholder="请输入订单号、客户姓名、手机号或收货地址"/>
		<br/><label style="margin-bottom: 15px;">送货日期：</label>
		<input id="createStartDate" name="createStartDate" type="text" maxlength="50" class="input-small Wdate" style="width: 100px;"
			onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true,maxDate:'#F{$dp.$D(\'createEndDate\');}'});" value="${createStartDate }"/>
		~
		<input id="createEndDate" name="createEndDate" type="text" maxlength="50" class="input-small Wdate" style="width: 100px;"
			onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true,minDate:'#F{$dp.$D(\'createStartDate\');}'});" value="${createEndDate }"/>
		<label>收货时间：</label>
		<!-- 
		<form:select id="slotId" path="timeSlot.id" class="required input-small">
			<option value="">请选择</option>
			<c:forEach items="${receiptTime.timeSlots}" var="timeSlot">
				<form:option value="${timeSlot.id}" label="${timeSlot.timeText}"/>
			</c:forEach>
       	</form:select>
		-->
		<span class="timeSlot">
     	<c:forEach items="${fns:getTimeSlotList()}" var="item">
     		<c:if test="${fn:contains(timeSlot,item)==false}">
				<input type="checkbox" name="timeVal" value="${item }">${item }
     		</c:if>
     		<c:if test="${fn:contains(timeSlot,item)==true}">
     			<input type="checkbox" name="timeVal" value="${item }" checked="checked">${item }
     		</c:if>
		</c:forEach>
		</span>
		<label>送货员 ：</label>
		<form:select id="memberId" path="deliveryIndent.deliveryMember.id" class="required input-small">
			<form:option value="" label="请选择"/>
			<form:options items="${fns:getDeliveryMemberList(1)}" itemLabel="name" itemValue="id" htmlEscape="false"/>
		</form:select>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" onclick="search()" value="搜索"/>
		<br/>
		&nbsp;<input id="btnSubmit1" class="btn btn-primary" type="button" onclick="showPurchaseOrder()" value="生成采购清单"/>
		&nbsp;<input id="btnSubmit1" class="btn btn-primary" type="button" onclick="showDistributionOrder()" value="生成配货清单"/>
		&nbsp;<input id="btnSubmit3" class="btn btn-primary" type="button" onclick="createDeliveryIndent()" value="指定送货员"/>
		&nbsp;<input id="btnSubmit4" class="btn btn-primary" type="button" onclick="checkout('')" value="送货员签出"/>
		&nbsp;<input id="btnSubmit4" class="btn btn-primary" type="button" onclick="exportOrder('')" value="订单导出"/>
		&nbsp;<input id="btnSubmit4" class="btn btn-primary" type="button" onclick="exportWord('')" value="导出派送单"/>
		<!-- 
		&nbsp;<input id="btnSubmit5" class="btn btn-primary" type="button" onclick="finishOrders()" value="完成订单"/>
		 -->
	</form:form>
	<tags:message content="${message}"/>
	<table id="contentTable" class="table table-bordered table-condensed" style="border-top: none; border-right: none; border-left: none; margin-bottom: 0px; padding-bottom: 5px;">
		<tr>
			<td><input type="checkbox" id="select_all" name="select_all" value="全选" onclick="selectAll();" style="margin-left: 22px;"/>全选</td>
		</tr>
	</table>
	<div id="listForm">
		<c:forEach items="${page.list}" var="order">
		<table id="contentTable" class="table table-bordered table-condensed" style="border-top: none; border-right: none; border-left: none; margin-bottom: 0px; padding-top:5px; padding-bottom: 5px;">
			<colgroup>
				<col width="50px"><col width="80px"><col width="90px"><col width="70px"><col width="100px"><col width="70px"><col width="120px"><col width="70px"><col width="400px">
			</colgroup>
			<tr>
				<td rowspan="4"  style="text-align: center;">
					<c:if test="${order.delFlag!='1'}">
					<input type="checkbox" id="orderId" name="orderId" value="${order.id }" />
					</c:if>
					<input type="hidden" id="delIndentId" name="delIndentId" value="${(order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.id != '') ? order.deliveryIndent.deliveryMember.id : ''}"/>
					<input type="hidden" id="orderType" name="orderType" value="${order.orderType }"/>
					<input type="hidden" id="delFlag" name="delFlag" value="${order.delFlag }"/>
					<input type="hidden" id="canDelivery" name="canDelivery" value="${order.canDelivery }" />
				</td>
				<td>${order.name}</td>
				<td>${order.phone }</td>
				<td>订单编号：</td>
				<td>
					<a href="javascript:" onclick="showDetail('${order.id}')">${order.orderNo}</a>
				</td>
				<td>下单时间：</td>
				<td><fmt:formatDate value="${order.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<td style="text-align: center;">
					<shiro:hasPermission name="ivm:order:view">
					<a href="javascript:" onclick="showDetail('${order.id}')">订单详情</a>
					</shiro:hasPermission>
				</td>
				<td rowspan="4" style="text-align: center;">
					<!-- 待付款 -->
					<c:if test="${order.workflowNode==1}">
					<img src="${ctxFront }/images/orderWorkFlow/small/1.png" height="50" width="400"/>
					</c:if>
					<!-- 已支付，处理中 -->
					<c:if test="${order.workflowNode==2}">
					<img src="${ctxFront }/images/orderWorkFlow/small/2.png" height="50" width="400"/>
					</c:if>
					<!-- 货到付款，处理中 -->
					<c:if test="${order.workflowNode==3}">
					<img src="${ctxFront }/images/orderWorkFlow/small/3.png" height="50" width="400"/>
					</c:if>
					<!-- 已支付，处理中，已指定送货员 -->
					<c:if test="${order.workflowNode==4}">
					<img src="${ctxFront }/images/orderWorkFlow/small/4.png" height="50" width="400"/>
					</c:if>
					<!-- 已支付，处理中，已指定送货员，配送中 -->
					<c:if test="${order.workflowNode==5}">
					<img src="${ctxFront }/images/orderWorkFlow/small/5.png" height="50" width="400"/>
					</c:if>
					<!-- 已支付，处理中，已指定送货员，配送中，已完成 -->
					<c:if test="${order.workflowNode==6}">
					<img src="${ctxFront }/images/orderWorkFlow/small/6.png" height="50" width="400"/>
					</c:if>
					<!-- 货到付款，处理中，已指定送货员 -->
					<c:if test="${order.workflowNode==7}">
					<img src="${ctxFront }/images/orderWorkFlow/small/7.png" height="50" width="400"/>
					</c:if>
					<!-- 货到付款，处理中，已指定送货员，配送中 -->
					<c:if test="${order.workflowNode==8}">
					<img src="${ctxFront }/images/orderWorkFlow/small/8.png" height="50" width="400"/>
					</c:if>
					<!-- 货到付款，处理中，已指定送货员，配送中，已完成 -->
					<c:if test="${order.workflowNode==9}">
					<img src="${ctxFront }/images/orderWorkFlow/small/9.png" height="50" width="400"/>
					</c:if>
				</td>
				<td rowspan="2" style="display:none">
					<c:if test="${order.delFlag=='0' && order.workflowNode==1}">
				    <!-- 待付款 -->
				    <label title="待付款" class="led_label" style="background-color: yellow;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==2}">
				    <!-- 已支付，处理中-->
				   	<label title="处理中" class="led_label" style="background-color: yellow;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==3}">
				    <!-- 货到付款，处理中-->
				    <label title="处理中" class="led_label" style="background-color: yellow;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==4}">
				    <!-- 已支付，已指定送货员-->
				    <label title="已指定送货员" class="led_label" style="background-color: yellow;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==5}">
				    <!-- 已支付，配送中-->
				    <label title="配送中" class="led_label" style="background-color: yellow;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==6}">
				    <!-- 已支付，已完成-->
				    <label title="已完成" class="led_label" style="background-color: green;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==7}">
				    <!-- 货到付款，已指定送货员-->
				    <label title="已指定送货员" class="led_label" style="background-color: yellow;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==8}">
				    <!-- 货到付款，配送中-->
				    <label title="配送中" class="led_label" style="background-color: yellow;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='0' && order.workflowNode==9}">
				    <!-- 货到付款，已完成 -->
				    <label title="已完成" class="led_label" style="background-color: green;">状态</label>
				    </c:if>
				    <c:if test="${order.delFlag=='1'}">
				    <!-- 已取消 -->
				    <label title="已取消" class="led_label" style="background-color: red;">库存</label>
				    </c:if>
				   	<c:if test="${order.canDelivery}">
				    <label title="库存有货" class="led_label" style="background-color: green;">库存</label>
				    </c:if>
				    <c:if test="${!order.canDelivery}">
				    <label title="库存不足" class="led_label" style="background-color: red;">库存</label>
				    </c:if>
				</td>
			</tr>
			<tr>
				<td>会员等级：</td>
				<td>暂无</td>
				<td>订单金额：</td>
				<td>
					<c:if test="${order.deliveryInfo==null}">${order.amount}</c:if><c:if test="${order.deliveryInfo!=null}">${order.deliveryInfo.amount}</c:if>元
				</td>
				<td>付款方式：</td>
				<td>
					<a href="javascript:" onclick="openPayType('${order.id}')">${fns:getEnumPayTypeDescByStatus(order.payType)}</a>
				</td>
				<td style="text-align: center;">
					<shiro:hasPermission name="ivm:order:view">
					<c:if test="${order.delFlag=='0' && order.confirm=='1'}">
					<a href="javascript:" onclick="showDeliveryDetail('${order.id}','${order.orderNo}')">送货单</a>
					</c:if>
					</shiro:hasPermission>
				</td>
			</tr>
			<tr>
				<td>上月订单数：</td>
				<td>暂无</td>
				<td>收货时间：</td>
				<td>${order.orderTimeText }</td>
				<td>送货员：</td>
				<td>${(order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.deliveryMember != null && order.deliveryIndent.deliveryMember.id != '') ? order.deliveryIndent.deliveryMember.name : '暂未分配' }</td>
				<td style="text-align: center;">
					<c:if test="${order.canDelivery && order.delFlag=='0' && order.orderType!='2'}">
				    <label title="库存有货" class="led_label" style="background-color: green;">库存</label>
				    </c:if>
				    <c:if test="${!order.canDelivery && order.delFlag=='0' && order.orderType!='2'}">
				    <label title="库存不足" class="led_label" style="background-color: red;">库存</label>
				    </c:if>
				</td>
			</tr>
			<tr>
				<td>平均客单价：</td>
				<td>暂无</td>
				<td>备注：</td>
				<td><p class="p_ellipsis" style="margin: 0px;" title="${order.remarks }">${order.remarks }</p></td>
				<td colspan="2">
					<c:if test="${order.delFlag=='0'}">
						<c:if test="${order.payStatus=='0' && order.payType != '1'}">
							等待付款
						</c:if>
						<c:if test="${((order.payStatus=='0' && order.payType == '1') || order.payStatus=='1') && order.confirm=='0'}">
							<a href="javascript:" onclick="showDetail('${order.id}')">等待确认</a>
						</c:if>
						<c:if test="${order.confirm=='1'}">
						<c:if test="${(order.payStatus=='0' && order.payType == '1') || order.payStatus=='1'}">
							<c:if test="${!(order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.deliveryMember != null && order.deliveryIndent.deliveryMember.id != '')}">
								<a href="javascript:" onclick="createDeliveryIndent('${order.id}')">指定送货员</a>
							</c:if>
						</c:if>
						<c:if test="${order.orderType=='0' && (order.deliveryIndent != null && order.deliveryIndent.id != null && order.deliveryIndent.id != '') && order.delFlag=='0'}">
							<a href="javascript:" onclick="checkout('${order.id}')">送货员签出</a>
						</c:if>
						<c:if test="${order.workflowNode=='5' || order.workflowNode=='8'}">
							<a href="javascript:" onclick="finishOrder('${order.id}')">订单完成</a>
						</c:if>
						<c:if test="${order.workflowNode=='6' || order.workflowNode=='9'}">
							<c:if test="${order.finish=='0'}">
								<a href="javascript:" onclick="finishPay('${order.id}')">解款</a>
							</c:if>
							<c:if test="${order.finish=='1'}">
								<span style="color: green;">订单已完成</span>
							</c:if>
							<c:if test="${order.finish=='2'}">
								<a href="javascript:" onclick="finishOrder('${order.id}')">等待复核</a>
							</c:if>
						</c:if>
						</c:if>
					</c:if>
					<c:if test="${order.delFlag=='1'}"><span style="color: green;">订单已取消</span></c:if>
				</td>
				<td style="text-align: center;">
					<shiro:hasPermission name="ivm:order:view">
					<c:if test="${order.orderType!='2' && order.delFlag=='0'}">
					<a href="javascript:;" onclick="cancelOrder('${order.id}')">取消订单</a>
					</c:if>
					</shiro:hasPermission>
				</td>
			</tr>
		</table>
		</c:forEach>
	</div>
	<div class="gotoTop"></div>
	<!-- div class="pagination">${page}</div -->
</body>
</html>
